package com.shop.user.atom.atomsvc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.common.model.InputBean;
import com.shop.common.model.ServiceBean;
import com.shop.common.model.param.user.MessageInput;
import com.shop.common.model.result.user.MessageOutput;
import com.shop.common.tmpl.BaseService;
import com.shop.common.util.state.MsgAcceptType;
import com.shop.user.atom.atomsvc.IMessageAtomSvc;
import com.shop.user.atom.dao.MessageMapper;
import com.shop.user.feign.resource.IResourceFeignClientSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 *
 * @author zhoulk
 * @date: 2019年05月03日  19:22
 */
@Service
public class MessageAtomSvc extends BaseService implements IMessageAtomSvc {

    @Autowired
    MessageMapper messageMapper;
    @Autowired
    IResourceFeignClientSvc resourceFeignClientSvc;

    @Override
    public Integer addMessage(MessageInput messageInput) {
        if (messageInput.getAccptType().intValue() ==  MsgAcceptType.PHONE.value()){
//            resourceFeignClientSvc.sendSmsMsg(messageInput.getAccptTip(),messageInput.getAccptPhone());
        }
        if (messageInput.getAccptType().intValue() ==  MsgAcceptType.EMAIL.value()){

        }
        return messageMapper.insertSelective(messageInput);
    }

    @Override
    public Integer modeMessage(MessageInput messageInput) {
        return messageMapper.updateByPrimaryKeySelective(messageInput);
    }

    @Override
    public MessageOutput qryMessage(MessageInput messageInput) {
        List<MessageOutput> list = messageMapper.qryMessageList(messageInput);
        if (list!=null){
            return list.get(0);
        }
        return null;
    }

    @Override
    public MessageOutput qryMessageById(Integer messageId) {
        return messageMapper.selectByPrimaryKey(messageId);
    }

    @Override
    public List<MessageOutput> qryMessageList(MessageInput messageInput) {
        return messageMapper.qryMessageList(messageInput);
    }

    @Override
    public ServiceBean<List<MessageOutput>> qryMessage4P(InputBean<MessageInput> inputBean) {
        PageHelper.startPage(inputBean.getIndex(),inputBean.getPageSize());
        List<MessageOutput> list = messageMapper.qryMessageList(inputBean.getParam());
        if (list==null){
            return resultFailed();
        }
        PageInfo<MessageOutput> pageInfo = new PageInfo<>(list);
        ServiceBean<List<MessageOutput>> serviceBean = new ServiceBean<>();
        serviceBean.setData(pageInfo.getList());
        serviceBean.setMaxSize(pageInfo.getTotal());
        return serviceBean;
    }

    @Override
    public Integer delMessageById(Integer messageId) {
        return messageMapper.deleteMessage(messageId);
    }

    @Override
    public Integer delMessageByCondition(MessageInput messageInput) {
        return null;
    }
}
